<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta http-equiv="x-dns-prefetch-control" content="on">
    <!-- <meta http-equiv="X-Frame-Options" content="ALLOW-FROM"> -->
    <title>享优乐抽奖记录</title>
    <link href="./image/favicon.ico" rel="shortcut icon">
    <link rel="stylesheet" href="./style/base.css" />
    <link rel="stylesheet" href="./style/layer.css" />
</head>

<body>
    <div class="fixed bg2"></div>
    <div class="content_jgg">
        <div class="content history-content">
            <h2 class="history-title">
                <div class="history-btn"></div>
            </h2>
            <div class="container">
                <div class="details">

                </div>
                <div class="btn-bar t-c">
                    <div class="btn-item hidden">
                        <button class="gradient-bg" id="address-btn">填写收货信息</button>
                    </div>
                    <div class="btn-item">
                        <button class="gradient-bg" id="back-btn">返回直播</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <!-- <script type="text/javascript" src="./js/common.js?v=20180719"></script> -->
    <script type="text/javascript" src="./js/layer.m.js"></script>
    <script type="text/javascript" src="./js/md5.js"></script>
    <script type="text/javascript">
        var urlSplit = window.location.href.split("/");
        var cardNo = JSON.parse(localStorage.getItem('isLogin') || '{}').staffNum;
        var common = {
            prize: {},
            urlPage: 'http://127.0.0.1:5500/static',
            // url: 'http://192.168.14.187:8090',
            url: window.location.protocol + "//" + window.location.host + "/" + urlSplit[3] + "/" + urlSplit[4],
            notice1: "目前参与人数较多，请稍后再试！"
        };
        var editAddressBtn = $('#address-btn');
        var t = +new Date();

        $.ajax({
            type: 'get',
            url: common.url + "/external/getServerConfig",
            dataType: "json",
            success: function (data) {

                if (!data.success) {
                    return;
                }

                var resp = JSON.parse(data.content.serverConfig);

                var tempKeys = [];

                for (var i = 0; i < resp.groupList.length; i++) {
                    tempKeys.push(resp.groupList[i]["group_id"]);
                }

                for (var j = 0; j < tempKeys.length; j++) {
                    var temp = resp[tempKeys[j]];
                    var tempData = {};
                    var tempCode = "";
                    for (var k = 0; k < temp.length; k++) {
                        if (temp[k]["type"] == "picture") {
                            tempData["url"] = temp[k]["url"];
                            tempData["position"] = temp[k]["key"];
                        }
                        if (temp[k]["key"] == "awardsName") {
                            tempData["title"] = temp[k]["value"];
                        }
                        if (temp[k]["key"] == "prizeType") {
                            tempData["status"] = temp[k]["value"];
                        }
                        if (temp[k]["key"] == "awardsCode") {
                            tempData["awardsCode"] = temp[k]["value"];
                            tempCode = temp[k]["value"];
                        }
                    }

                    common.prize[tempCode] = tempData;

                }

                common["deploycolId"] = data.content.deploycolId;

                $.ajax({
                    url: common.url + "/auldraw/winner/record?dealerNo=" + JSON.parse(localStorage.getItem("isLogin")).staffNum,
                    type: 'GET',
                    dataType: "json",
                    success: function (data) {

                        if (data && data.content && !data.content.dealerNo) {

                            if (data && data.content) {

                                var keys = Object.keys(data.content);

                                for (var i = 0; i < keys.length; i++) {

                                    var realityString = '';

                                    var virtualString = '';

                                    var str = $('.details').html();;

                                    if (common.prize[data.content[keys[i]].giftCode].status === "1") {

                                        if (!data.content[keys[i]]["detailAddress"]) {
                                            realityString = '<a style="color: inherit;margin-left:10px" href="./address.html' + '?qualiSeqNo=' + keys[i] + '">' + '点此填写收货地址</a>'
                                        } else {
                                            realityString = '<a style="color: inherit;margin-left:10px" href="./addressDetails.html' + '?receiverName=' + data.content[keys[i]]["receiverName"] + '&&' + 'receiverPhone=' + data.content[keys[i]]["receiverPhone"] + '&&' + 'cityCode=' + data.content[keys[i]]["cityCode"] + '&&' + 'detailAddress=' + data.content[keys[i]]["detailAddress"]  + '&&' + 'provinceCode=' + data.content[keys[i]]["provinceCode"] + '&&' + 'townCode=' + data.content[keys[i]]["townCode"] + '">' + '查看地址</a>'
                                        }

                                    } else if (common.prize[data.content[keys[i]].giftCode].status === "0") {
                                        virtualString = ""
                                    }

                                    str = str + '<p>恭喜您获得<span class="yellow">' + common.prize[data.content[keys[i]].giftCode].title + realityString + virtualString + '!</span></p>';
                                
                                    $('.details').html(str);
                                }

                            } else {
                                $('.details').html('<p class="t-c">暂无中奖纪录</p>');
                            }
                            return
                        } 
                        else {

                            // if (data && data.content) {

                            //     var realityString = '';

                            //     var virtualString = '';

                            //     var str = '';

                            //     str = str + '<p>恭喜您获得<span class="yellow">' + common.prize[data
                            //         .content.awardsId].title + '!</span></p>';
                            //     if (common.prize[data.content.awardsId].status === "1") {
                            //         realityString = "<p>请填写收货地址,公司将在2周内配送！谢谢参与!</p>"
                            //     } else if (common.prize[data.content.awardsId].status === "0") {
                            //         virtualString = "<p>公司将在2周内发放,后期可登录纷享荟“我的”进行查询！谢谢参与!</p>"
                            //     }

                            //     str = str + realityString + virtualString;

                            //     $('.details').html(str);


                            //     if (common.prize[data.content.awardsId].status === "1") { // 实物需要显示地址按钮
                            //         if (!data.content.detailAddress) {
                            //             editAddressBtn.attr('data-qualiSeqNo', data.content.qualiSeqNo);
                            //         } else {
                            //             editAddressBtn.attr('data-receiverName', data.content.receiverName);
                            //             editAddressBtn.attr('data-receiverPhone', data.content.receiverPhone);
                            //             editAddressBtn.attr('data-cityCode', data.content.cityCode);
                            //             editAddressBtn.attr('data-detailAddress', data.content.detailAddress);
                            //             editAddressBtn.attr('data-cityCode', data.content.cityCode);
                            //             editAddressBtn.attr('data-townCode', data.content.townCode);
                            //         }
                                    
                            //         editAddressBtn.attr('data-type', data.content.detailAddress)
                            //             .text(
                            //                 data.content.detailAddress ? '查看收货信息' :
                            //                 '填写收货信息')
                            //             .parent()
                            //             .removeClass('hidden');
                            //     }
                            // } else {
                            //     $('.details').html('<p class="t-c">暂无中奖纪录</p>');
                            // }
                            // return
                        }

                    }
                })

            },
        });

        //抓取接口错误404,503,500
        $(document).ajaxError(function (event, jqXHR, options, errorMsg) {
            if (jqXHR.status == 404 || jqXHR.status == 503 || jqXHR.status == 500 || jqXHR.status == 0) {
                layer.closeAll();
                layer.open({
                    type: 3,
                    title: '温馨提示',
                    className: 'errortNotice',
                    content: '<div class="notice">' + common.notice1 +
                        '</div><div class="button">确定</div>',
                    style: 'width:17rem; background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                    shadeClose: false
                });
                $(".errortNotice  .button").on("click", function () {
                    location.reload();
                })
            }
        });

        function formatDate(d) {
            var date = new Date(d);
            return date.getFullYear() + '-' + formatNum(date.getMonth() + 1) + '-' + formatNum(date.getDate()) + ' ' +
                formatNum(date.getHours()) + ':' + formatNum(date.getMinutes()) + ':' + formatNum(date.getSeconds());
        }

        function formatNum(num) {
            return num >= 10 ? num : '0' + num;
        }
        $('#address-btn').on('click', function (e) {
            var cur = $(this);
            var type = cur.attr('data-type');
            location.href = (type ? './addressDetails.html' + '?receiverName=' + cur.attr('data-receiverName') + '&&' + 'receiverPhone=' + cur.attr('data-receiverPhone') + '&&' + 'cityCode=' + cur.attr('data-cityCode') + '&&' + 'detailAddress=' + cur.attr('data-detailAddress') + '&&' + 'provinceCode=' + cur.attr('data-provinceCode') + '&&' + 'townCode=' + cur.attr('data-townCode') : './address.html' + '?qualiSeqNo=' + cur.attr('data-qualiSeqNo'));
        })
        $('#back-btn').on('click', function (e) {
            location.href = common.skipUrl;
        })
    </script>
    <style>
        #cnzz_stat_icon_1275024165 {
            display: none;
        }
    </style>
    <script type="text/javascript">
        var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
        document.write(unescape("%3Cspan id='cnzz_stat_icon_1275024165'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol +
            "s19.cnzz.com/z_stat.php%3Fid%3D1275024165' type='text/javascript'%3E%3C/script%3E"));
    </script>
</body>

</html>